﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Configuration;
using System.Data.OleDb;
using System.Data.Sql;
using System.Data;
using InterFaceFinance;


namespace DataAccess
{
    public class ClsJournalDB : IJournalDB
    {
       

        private Database objDatabase = DatabaseFactory.CreateDatabase("Connection String");
        
        public object getData()
        {
            return objDatabase.ExecuteReader(CommandType.StoredProcedure, "Query1");
        }

      

        public int InsertJournals(IJournal iJournal)
        {
           int intJournalid;
           intJournalid= objDatabase.ExecuteNonQuery("InsertJournal", iJournal.ReceiptNumber, iJournal.JournalDate, iJournal.Description,iJournal.AccPeriod,iJournal.CompanyID);
          
           return intJournalid;
        }
        public void InsertJournalTransaction(int intJournalid, double dblAmount, int intChartofAccountid, int intDebitCredit)
        {
          objDatabase.ExecuteNonQuery("InsertJournalTransactions", intJournalid, dblAmount,intChartofAccountid,intDebitCredit);
        }


        public object LoadDBAccounts(int CompanyId)
        {
          return objDatabase.ExecuteDataSet("usp_getaccounttype",CompanyId);
        }

        public object LoadDBJournal(int JournalId)
        {
            return objDatabase.ExecuteDataSet("usp_getJournals",JournalId);
        }

        public object EditDBJournal(int JournalId)
        {
            return objDatabase.ExecuteDataSet("usp_getJournals", JournalId);
        }

        public object LoadChartofAccount(int CompanyId)
        {
            return objDatabase.ExecuteDataSet("usp_getChartofAccounts",CompanyId);
        }

        public object EditChartofAccount(int ChartofAccountID, int ChartofAccID, int CompanyId)
        {
            return objDatabase.ExecuteDataSet("usp_getChartofAccounts",ChartofAccountID,ChartofAccID,CompanyId);
        }

        public object LoadFinancialYear(string currdate,int CompanyId)
        {
            return objDatabase.ExecuteDataSet("usp_getFinancialYear",currdate,CompanyId);
        }

        public object LoadControlofAccounts(int CompanyId)
        {
            return objDatabase.ExecuteDataSet("usp_getControlofAccounts",CompanyId);
        }


        public object LoadControlofAccounts_ProfitLoss(int CompanyId)
        {
            return objDatabase.ExecuteDataSet("usp_getControlofAccounts_ProfitLoss",CompanyId);
        }


        public object LoadControlofAccounts_BalanceSheet(int CompanyId)
        {
            return objDatabase.ExecuteDataSet("usp_getControlofAccounts_BalanceSheet",CompanyId);
        }


        public object LoadSingleControlofAccounts(int ChartofAccID, int CompanyId)
        {
            return objDatabase.ExecuteDataSet("usp_journalChart", ChartofAccID,CompanyId);
        }


        public int InsertChartofAccountDB(IChartofAccounts IChartofAccount,bool IsControl)
        {
            int intChartID;
            int ChartofAccountID;

            if (IsControl == true)
            {
                 ChartofAccountID = 0;
            }
            else
            {
                ChartofAccountID = IChartofAccount.ChartofAccID;
                
            }
            intChartID = objDatabase.ExecuteNonQuery("usp_InsertChartofAccount", IChartofAccount.AccountNumber, IChartofAccount.Description,ChartofAccountID, IChartofAccount.AccountTypeID, IChartofAccount.Company_id);

            return intChartID;
        }



        public object UpdateFinancialYear(int Yearid,ICloseAccount ICloseAcc)
        {
            int financialID;
            financialID = Convert.ToInt16(objDatabase.ExecuteDataSet("usp_updatefinancialyear", Yearid, ICloseAcc.StartDate,ICloseAcc.EndDate,ICloseAcc.Company_id));
            return financialID;
        }


        
    }



   
   
}
